<template>
  <van-address-list v-model="chosenAddressId" :list="list" @add="onAdd" @edit="onEdit" />
</template>

<script lang="ts" setup>
import { getAddressApi} from '@/api/address';
import type {IAddress} from '@/types/address';
import { ref, reactive } from 'vue';
import { useRouter, useRoute } from 'vue-router';

const route = useRoute();
const router = useRouter();
const chosenAddressId = ref(1);
const list = ref<IAddress[]>([]);

getAddressApi().then((res) => {
  list.value = res;
});

const onAdd = () => {
  router.push('/address/add');
};
const onEdit = (val: IAddress) => {
  router.push({
    path: '/address/edit',
    query: { item: JSON.stringify(val) },
  });
};
</script>

<style lang="scss" scoped></style>
